%%-*- mode: erlang -*-
{minimum_otp_vsn, "22.0"}.

%fail_on_warning,
{erl_opts, [
    debug_info,
    {platform_define, "20|21|22|23|24|25|26", nowarn_gen_fsm},
    {platform_define, "^(R|1|20|21|22|23|24|25|26)"}
]}.

{edoc_opts, [{preprocess, true}]}.

{project_plugins, [
    {rebar3_cuttlefish, {git, "https://github.com/vernemq/rebar3_cuttlefish", {branch, "master"}}},
    erlfmt
]}.

{dialyzer, [{exclude_mods, [vmq_plugin]}, {plt_location, "plts"}, {base_plt_location, "plts_base"}]}.

{deps, [
    {recon, "2.5.4"},
    {replayq, {git, "https://github.com/emqx/replayq.git", {branch, "master"}}},
    {stdout_formatter, "0.2.4"},
    {cuttlefish, {git, "https://github.com/Kyorai/cuttlefish.git", {tag, "v3.2.0"}}},
    {vernemq_dev, {git, "https://github.com/vernemq/vernemq_dev.git", {branch, "master"}}},
    {syslog, "4.0.0", {pkg, syslog_app}},
    {clique, {git, "https://github.com/vernemq/clique.git", {tag, "0.3.7-verne"}}}
]}.

{overrides,
    %% overrides to get it compiling on OTP 21
    [{override, clique, [{erl_opts, [debug_info]}]}]}.

{erlfmt, [
    write,
    {print_width, 100},
    {files, [
        "apps/*/{src,include}/*.{erl,hrl,app.src,config}",
        "apps/*/rebar.config",
        "rebar.config",
        "vars.config",
        "pkg.vars.config"
    ]},
    {exclude_files, []}
]}.

{profiles, [
    {test, [
        {erl_opts, [nowarn_export_all]},
        %% create junit xml for CI
        {ct_opts, [
            {ct_hooks, [cth_surefire]}
        ]},
        {cover_enabled, true}
    ]},
    {all_tests, [{erl_opts, [{d, run_all_tests, true}]}]},
    {ci_tests, [{erl_opts, [{d, run_ci_tests, true}]}]}
]}.

{cuttlefish, [{schema_dir, "lib"}, {schema_discovery, false}]}.

{relx, [
    {release, {vernemq, semver}, [
        sasl,
        inets,
        xmerl,
        compiler,
        vmq_server,
        vernemq_dev,
        credentials_obfuscation,
        {cuttlefish, load},
        {vmq_plumtree, load},
        {plumtree, load},
        {vmq_generic_msg_store, load},
        {vmq_passwd, load},
        {vmq_acl, load},
        {vmq_bridge, load},
        {vmq_diversity, load},
        {vmq_webhooks, load},
        {vmq_swc, load},
        {vmq_pulse, load},
        {recon, load},
        {runtime_tools, load},
        {tools, load},
        {mcd, load},
        {vmq_mqtt5_demo_plugin, load},
        {vmq_http_pub, load},
        {replayq, load},
        {vmq_web_ui, load}
    ]},
    % the vars.generated is created by the Makefile
    {overlay_vars, "vars.generated"},
    {dev_mode, false},
    {include_erts, true},
    {include_src, false},
    % we're using the runner from files/runner (ex. node_package)
    {extended_start_script, false},
    {overlay, [
        {mkdir, "data/broker"},
        {mkdir, "data/msgstore"},
        {mkdir, "log/sasl"},
        {template, "files/vmq-admin", "bin/vmq-admin"},
        {template, "files/runner", "bin/vernemq"},
        {template, "files/env.sh", "lib/env.sh"},
        {copy, "3rd-party-licenses.txt", "share/3rd-party-licenses.txt"},
        {copy, "files/nodetool", "erts-{{erts_vsn}}/bin/nodetool"},
        {copy, "_build/default/bin/cuttlefish", "erts-{{erts_vsn}}/bin/cuttlefish"},
        {copy, "apps/vmq_acl/priv/default.acl", "etc/vmq.acl"},
        {copy, "apps/vmq_passwd/priv/vmq_passwd", "bin/vmq-passwd"},
        %% the runner script expects vernemq.boot and vernemq.script instead of the default start.boot/.script
        {copy, "_build/default/rel/vernemq/releases/{{release_version}}/start.boot",
            "releases/{{release_version}}/vernemq.boot"},
        {copy, "_build/default/rel/vernemq/releases/{{release_version}}/start.script",
            "releases/{{release_version}}/vernemq.script"},
        %% Cuttlefish Schema Files have a priority order.
        %% Anything in a file prefixed with 00- will override
        %% anything in a file with a higher numbered prefix.
        %%
        %% Please only use 0[0-9]-*.schema for development purposes
        {template, "apps/vmq_server/priv/vmq_server.schema", "share/schema/10-vmq_server.schema"},
        {template, "apps/vmq_generic_msg_store/priv/vmq_generic_msg_store.schema",
            "share/schema/11-vmq_generic_msg_store.schema"},
        {template, "apps/vmq_plugin/priv/vmq_plugin.schema", "share/schema/12-vmq_plugin.schema"},
        {template, "apps/vmq_acl/priv/vmq_acl.schema", "share/schema/13-vmq_acl.schema"},
        {template, "apps/vmq_passwd/priv/vmq_passwd.schema", "share/schema/14-vmq_passwd.schema"},
        {template, "apps/vmq_diversity/priv/vmq_diversity.schema",
            "share/schema/15-vmq_diversity.schema"},
        {template, "apps/vmq_diversity/priv/vmq_bcrypt.schema",
            "share/schema/16-vmq_bcrypt.schema"},
        {copy, "apps/vmq_diversity/priv/init.lua", "share/lua/init.lua"},
        {copy, "apps/vmq_diversity/priv/auth", "share/lua/"},
        {template, "apps/vmq_webhooks/priv/vmq_webhooks.schema",
            "share/schema/17-vmq_webhooks.schema"},
        {template, "apps/vmq_bridge/priv/vmq_bridge.schema", "share/schema/18-vmq_bridge.schema"},
        {template, "apps/vmq_swc/priv/vmq_swc.schema", "share/schema/19-vmq_swc.schema"},
        {template, "apps/vmq_pulse/priv/vmq_pulse.schema", "share/schema/20-vmq_pulse.schema"},
        {template, "apps/vmq_http_pub/priv/vmq_http_pub.schema",
            "share/schema/21-vmq_http_pub.schema"},
        {template, "apps/vmq_web_ui/priv/vmq_web_ui.schema", "share/schema/22-vmq_web_ui.schema"},
        {template, "files/vmq.schema", "share/schema/30-vmq.schema"},
        {template, "_build/default/lib/cuttlefish/priv/erlang_vm.schema",
            "share/schema/31-erlang_vm.schema"},
        {template, "_build/default/lib/riak_sysmon/priv/riak_sysmon.schema",
            "share/schema/32-riak_sysmon.schema"},
        {template, "_build/default/lib/eleveldb/priv/eleveldb.schema",
            "share/schema/33-eleveldb.schema"},
        {mkdir, "lib/erlio-patches"}
    ]}
]}.
